package com.lushu.helpers.structure
{
	import com.lushu.data.Zone;
	import com.lushu.data.ZoneInfo;
	
	public class ZoneFactory
	{
		public static function createZone(mapName : String, callback : Function, existingZoneInfo : ZoneInfo = null) : Zone
		{
			var fileName : String = mapName;
			fileName.replace(" ","_");
			var mapName : String = fileName.split(".")[0];
			var zone : Zone;
			var fileLoad : XML
			if(existingZoneInfo != null)
			{
				fileLoad = XML('<zone name="'+mapName+'" file="'+fileName+'"/>');
			}
			else
			{
				fileLoad = XML('<zone name="'+mapName+'" file="default.map"/>');
			}
			zone = new Zone(fileLoad);
			zone.setName(mapName);
			zone.addEventListener("zoneLoaded", callback);
			
			return zone;
		}

	}
}